<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use payClass\QRcode;
use payClass\pay\Config;

$db     = new Datebase();
$config = new Config();

$param = $db->param();
// $param = [
// 	'typeid' => '108',
// 	'scanType' => 'web',
// 	'price' => '600',
// 	'uid' => '4',
// ];

switch ($param['scanType']) {
	case 'wx':
		$subUrl = 'http://interface.yjfpay.com:8081/pay.do';
		break;

	case 'wx_wap':
		$subUrl = 'http://interface.yjfpay.com:8081/pay.do';
		break;

	case 'alipay':
		$subUrl = 'http://interface.yjfpay.com:8082/pay.do';
		break;

	case 'alipay_wap':
		$subUrl = 'http://interface.yjfpay.com:8082/pay.do';
		break;

	case 'alipayhb':
		$subUrl = 'http://interface.yjfpay.com:8082/pay.do';
		break;

	case 'alipayhb_wap':
		$subUrl = 'http://interface.yjfpay.com:8082/pay.do';
		break;

	case 'qq':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'qq_wap':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'jd':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'jd_wap':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'yl':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'yl_wap':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'mb':
		$subUrl = 'http://interface.yjfpay.com:8082/pay.do';
		break;

	case 'mb_wap':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'web':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	case 'quick':
		$subUrl = 'http://interface.yjfpay.com:8080/pay.do';
		break;

	default:
		$subUrl = '';
		break;
}

$dataArray['version']    = '1.0';
$dataArray['mer_id']     = Config::$merchant;
$dataArray['order_id']   = $param['orderNumber'] = 'C' . time() . 'U' . $param['uid'];
$dataArray['price']      = $param['price'] * 100;
$dataArray['notify_url'] = Config::$notifyUrl;
$dataArray['pay_type']   = $param['scanType'];
$dataArray['randomid']   = time();
$dataArray['sign']       = Config::getSign($dataArray, Config::$key);
$dataArray['attach']     = $param['uid'];
$dataArray['return_url'] = Config::$merUrl;

$param['paytype'] = Config::$folder.'-'.Config::$merchant;
$verifyRes = $db->verifyScan($param);
if ($verifyRes != 'Y') $db->ajaxReturn($verifyRes);

$curlRes  = Config::post($dataArray, $subUrl);
$resArray = json_decode($curlRes, true);
if ($resArray['code'] != '00') $db->ajaxReturn($resArray['message']);

$resData = json_decode($resArray['data'], true);
$db->ajaxReturn($resData['qrcode_url']);